/*
 * XMLImportTest.java
 * JMUnit based test
 *
 * Created on Dec 1, 2009, 10:32:16 PM
 */

package ocbn.remotelab.test_package;

import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import jmunit.framework.cldc10.*;
import ocbn.remotelab.events.Event;
import ocbn.remotelab.events.MassSpectrometerStateEvent;
import ocbn.remotelab.events.MassSpectrometerStateEvent.State;
import ocbn.remotelab.xml.*;
import ocbn.remotelab.util.date.*;

/**
 * @author Basem
 */
public class XMLImportTest extends TestCase {

    //Declaring the event objects
        Calendar cal1;
        Calendar cal2;
        Date d1;
        Date d2;

    public XMLImportTest() {
      //The first parameter of inherited constructor is the number of test cases
        super(1,"XMLImportTest");
    }

    public void test(int testNumber) throws Throwable {
        switch (testNumber) {
            case 0:
                testImportXML();
                break;
            default:
                break;
        }
    }

    /**
     * Test of testImportXML method, of class XMLImport.
     */
    public void testImportXML() throws AssertionFailedException {
        System.out.println("importXML");

        XMLImport instance = new XMLImport();

        //XML in compact form
        String XML_1 =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<data><event type=\"MS State\"><id>0x0001</id>" +
                "<time>Oct 3, 2009 10:12:25 AM</time><state>failed</state>" +
                "<source>MS #1</source><details>Analyst terminated." +
                "Error code: 0x0000036</details></event><event type=\"MS State\">" +
                "<id>0x0002</id><time>Oct 6, 2009 05:34:49 PM</time><state>completed</state><source>" +
                "MS #2</source></event></data>";

        cal1 = Calendar.getInstance();
        cal1.set(Calendar.YEAR, 2009);
        cal1.set(Calendar.MONTH, 9);
        cal1.set(Calendar.DAY_OF_MONTH, 3);
        cal1.set(Calendar.HOUR, 10);
        cal1.set(Calendar.AM_PM, Calendar.AM);
        cal1.set(Calendar.MINUTE, 12);
        cal1.set(Calendar.SECOND, 25);
        cal1.set(Calendar.MILLISECOND, 0);
        d1 = cal1.getTime();
        ocbn.remotelab.util.date.Date dd = new ocbn.remotelab.util.date.Date(d1);

        Event e1 = new MassSpectrometerStateEvent(0x0001, State.FAILED, "MS #1", 
                dd, "Analyst terminated.Error code: 0x0000036");
        
        cal2 = Calendar.getInstance();
        cal2.set(Calendar.YEAR, 2009);
        cal2.set(Calendar.MONTH, 9);
        cal2.set(Calendar.DAY_OF_MONTH, 6);
        cal2.set(Calendar.HOUR, 5);
        cal2.set(Calendar.AM_PM, Calendar.PM);
        cal2.set(Calendar.MINUTE, 34);
        cal2.set(Calendar.SECOND, 0);
        cal2.set(Calendar.MILLISECOND, 0);
         d2 = cal2.getTime();
        ocbn.remotelab.util.date.Date ddd = new ocbn.remotelab.util.date.Date(d2);
        Event e2 = new MassSpectrometerStateEvent(0x0002, State.COMPLETED
                , "MS #2", ddd);
       
 
        Vector result_1 = instance.importXML(XML_1);
        assertEquals(e1.toString(), result_1.elementAt(0).toString());
        assertEquals(e2.toString(), result_1.elementAt(1).toString());



    }
}
